package com.example.shaoying.yuejian.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.adapter.TrainAdapter;
import com.example.shaoying.yuejian.javabean.Train;
import com.example.shaoying.yuejian.model.ClubeModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class TrainFragment extends Fragment {

    private View view;
    private RecyclerView recyclerView;
    private List<Train> data;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
         view= inflater.inflate(R.layout.tab01, container, false);
        recyclerView= (RecyclerView) view.findViewById(R.id.re_peixunlist);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        initData();
        return view;
    }
    private void initData() {
        ClubeModel listsmodel=new ClubeModel();
        Call<List<Train>> call=listsmodel.getlistsTraining();
        call.enqueue(new Callback<List<Train>>() {
            @Override
            public void onResponse(Call<List<Train>> call, Response<List<Train>> response) {
                data=response.body();
                recyclerView.setAdapter(new TrainAdapter(getActivity(),data));
            }

            @Override
            public void onFailure(Call<List<Train>> call, Throwable t) {

            }
        });
    }
}
